<template>
	<view>
		<view class="uni-padding-wrap uni-common-mt" style="width: 100%;">
			<view class="uni-title uni-common-mt">
				<text>设备二维码</text>
			</view>
			<view class="uni-flex uni-row">
				<view style="width: 100%;"><img :src="myQRCode" style="width: 600rpx;height: 600rpx;" /></view>
			</view>
		</view>
		<!-- <view class="footer">
			<text class="submit" @click="saveImageToPhotosAlbum">保存图片到相册</text>
		</view> -->
	</view>
</template>

<script>
	import Api from '@/common/api';
	import {
		mapState,
		mapMutations
	} from 'vuex';
	export default {
		components: {
		},
		data() {
			return {
				myQRCode: '',
				deviceId: '',
			};
		},
		computed: {
			...mapState(['userInfo']),
		},
		onLoad(options) {
			this.deviceId = options.deviceId;
			this.getQrCode();
		},
		methods: {
			async getQrCode() {
				let that = this;
				let params = {
					"deviceId": that.deviceId
				}
				let data = await Api.apiCall('get', Api.qsg.getDeviceQRcode, params);
				if(data){
					that.myQRCode = data.qrcode;
				}
			},
			// saveImageToPhotosAlbum(){
			// 	var that = this;
			// 	uni.authorize({
			// 		scope: 'scope.writePhotosAlbum',
			// 		success: () => {
			// 			uni.downloadFile({
			// 				url: that.myQRCode, 
			// 				success: (res) => {
			// 					console.log("statusCode====" + res.statusCode);
			// 					if (res.statusCode === 200) {
			// 						let file = res.tempFilePath;
			// 						//that.save(file)
			// 						console.log("filePpath====" + file);
			// 						uni.saveImageToPhotosAlbum({
			// 							filePath: file,
			// 							success: () => {
			// 								that.$core.msg("保存成功.");
			// 							},
			// 							faile:(err)=>{
			// 								console.log('失败！' + JSON.stringify(err))
			// 							}
			// 						}); 

			// 					}
			// 				}
			// 			});
			// 		},
			// 		fail() {
			// 			uni.showModal({
			// 				title: '图片保存失败',
			// 				content: '请确认是否已开启授权',
			// 				confirmText: '开启授权',
			// 				success(res) {
			// 					if (res.confirm) {
			// 						uni.openSetting({
			// 							success(settingdata) {
			// 								if (settingdata.authSetting["scope.writePhotosAlbum"]) {
			// 									uni.showToast({
			// 										title: '授权成功，请重试哦~',
			// 										icon: "none"
			// 									});
			// 								} else {
			// 									uni.showToast({
			// 										title: '请确定已打开保存权限',
			// 										icon: "none"
			// 									});
			// 								}
			// 							}
			// 						})
			// 					}
			// 				}
			// 			})
			// 		}
			// 	})
			// },
			// save(url){
			// 	let that = this;
			// 	uni.showLoading({
			// 	    title: '保存中'
			// 	});
			// 	uni.saveImageToPhotosAlbum({
			// 		filePath: url,
			// 		success: () => {
			// 			uni.hideLoading();
			// 			that.$core.msg("保存成功.");
			// 		},
			// 		fail: () => {
			// 			uni.hideLoading();
			// 			that.$core.msg("保存失败.");
			// 		},
			// 		complete: () => {
					
			// 		}
			// 	});
			// }
		}
	}
</script>

<style lang="scss">
	page {
		background: $page-color-base;
	}
	
	.flex-item {
			width: 50%;
			height: 200upx;
			text-align: center;
			line-height: 200upx;
		}
	
		.flex-item-V {
			width: 100%;
			height: 150upx;
			text-align: center;
			line-height: 150upx;
		}
	
		.text {
			margin: 15upx 10upx;
			padding: 0 20upx;
			background-color: #ebebeb;
			height: 70upx;
			line-height: 70upx;
			text-align: center;
			color: #777;
			font-size: 26upx;
		}
	
	.list-cell {
		display: flex;
		align-items: baseline;
		padding: 20upx $page-row-spacing;
		line-height: 60upx;
		position: relative;
		background: #fff;
		justify-content: center;

		&.log-out-btn {
			margin-top: 40upx;

			.cell-tit {
				color: $uni-color-primary;
				text-align: center;
				margin-right: 0;
			}
		}

		&.cell-hover {
			background: #fafafa;
		}

		&.b-b:after {
			left: 30upx;
		}

		&.m-t {
			margin-top: 16upx;
		}

		.cell-more {
			align-self: baseline;
			font-size: $font-lg;
			color: $font-color-light;
			margin-left: 10upx;
		}

		.cell-tit {
			flex: 1;
			font-size: $font-base + 2upx;
			color: $font-color-dark;
			margin-right: 10upx;
		}

		.cell-tip {
			font-size: $font-base;
			color: $font-color-light;
		}

		switch {
			transform: translateX(16upx) scale(.84);
		}
	}
	
	.footer {
		position: fixed;
		left: 0;
		bottom: 0;
		z-index: 995;
		display: flex;
		align-items: center;
		width: 100%;
		height: 90upx;
		justify-content: space-between;
		font-size: 30upx;
		background-color: #fff;
		z-index: 998;
		color: $font-color-base;
		box-shadow: 0 -1px 5px rgba(0, 0, 0, 0.1);

	
		.submit {
			display: flex;
			align-items: center;
			justify-content: center;
			width: 100%;
			height: 100%;
			color: #fff;
			font-size: 26upx;
			background-color: #e61a0f;
		}
	}
</style>
